package com.qeegoo.b2bautozityp.moudle.good.view.category;

import android.app.Activity;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.view.Gravity;

import com.qeegoo.b2bautozityp.R;
import com.qeegoo.b2bautozityp.databinding.ActivityGoodsCategoryBinding;
import com.qeegoo.b2bautozityp.injector.component.DaggerGoodsActivityComponent;
import com.qeegoo.b2bautozityp.moudle.base.BaseActivity;
import com.qeegoo.b2bautozityp.moudle.good.viewmodel.category.GoodsCategoryViewModel;

import javax.inject.Inject;

/**
 * 王少岩 在 2017/9/20 创建了它
 */

public class GoodsCategoryActivity extends BaseActivity<ActivityGoodsCategoryBinding> {
    @Inject
    GoodsCategoryViewModel mViewModel;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_goods_category;
    }

    @Override
    protected void initInjector() {
        DaggerGoodsActivityComponent.builder().appComponent(getAppComponent()).activityComponent(getActivityComponent()).build().inject(this);
    }

    @Override
    protected void initViews() {
        mBinding.setViewModel(mViewModel);
        mBinding.rvCategory.setAdapter(mViewModel.getAdapter());
    }

    public void openGoodsCategoryFrag(Fragment fragment) {
        getSupportFragmentManager().beginTransaction().replace(R.id.layout_container, fragment).commit();
        mBinding.layoutDrawer.openDrawer(Gravity.RIGHT);
    }

    public void closeFrag() {
        mBinding.layoutDrawer.closeDrawer(Gravity.RIGHT);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != RESULT_OK) return;
        if (requestCode == 1000) {
            setResult(Activity.RESULT_OK, data);
            finish();
        }
    }
}
